package com.project.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("session")
public class SessionController {

    @RequestMapping("getInfo")
    public String getInfo(HttpServletRequest req){
        //得到session会话对象
        HttpSession session = req.getSession();
        //设置session过期时间为10分种
        session.setMaxInactiveInterval(10);
        //从session中，得到共享信息
        String value = (String)session.getAttribute("session");

//        //得到session对象的唯一标识
//        return session.getId();
        return "共享信息："+value+"   sessionId="+session.getId();
    }

    @RequestMapping("addInfo")
    public String addInfo(HttpServletRequest req){
        //得到session会话对象
        HttpSession session = req.getSession();
        //在session中绑定共享信息
        session.setAttribute("session","session共享信息");

        return "添加信息成功";
    }
}
